﻿package com.tudou.cookie
{
    import com.tudou.consts.*;
    import com.tudou.model.*;
    import com.tudou.track.*;

    public class UserLog extends Object
    {
        private var isOverDue:Boolean = false;
        private var keyTime:Number;
        private var baseInfo:IBaseInfo;
        private static var instance:UserLog = null;

        public function UserLog()
        {
            return;
        }// end function

        public function addNode(param1:String, param2:Array = null) : void
        {
            if (isOverDue)
            {
                return;
            }
            if (param2 == null)
            {
                param2 = [];
            }
            var _loc_3:Array = [];
            _loc_3 = _loc_3.concat(param1, param2, new Date().time);
            saveLog(_loc_3.join("|"), param1 == NodeLog.VIDEO_REQUEST_ERROR ? (1) : (0));
            return;
        }// end function

        public function reset() : void
        {
            isOverDue = false;
            keyTime = new Date().time;
            return;
        }// end function

        protected function saveLog(param1:String, param2:int) : void
        {
            var _loc_6:Object = null;
            var _loc_7:Array = null;
            var _loc_3:* = TudouSO.getInstance();
            var _loc_4:* = _loc_3.getValue(CookieConsts.USER_LOG_LIST);
            if (_loc_3.getValue(CookieConsts.USER_LOG_LIST) == null)
            {
                _loc_4 = [];
            }
            var _loc_5:Boolean = false;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_4.length)
            {
                
                _loc_6 = _loc_4[_loc_8];
                if (keyTime == _loc_6["keyTime"])
                {
                    _loc_5 = true;
                    break;
                }
                _loc_8++;
            }
            if (_loc_5)
            {
                _loc_7 = _loc_6["nodes"];
                _loc_7.push(param1);
                _loc_6["error"] = _loc_6["error"] + param2;
                _loc_3.setValue(CookieConsts.USER_LOG_LIST, _loc_4);
            }
            else
            {
                isOverDue = _loc_4.length > 0 && _loc_4[0]["keyTime"] > keyTime;
                if (!isOverDue)
                {
                    while (_loc_4.length >= 10)
                    {
                        
                        _loc_4.shift();
                    }
                    _loc_7 = [];
                    _loc_7.push(param1);
                    _loc_6 = {keyTime:keyTime, nodes:_loc_7, error:0};
                    _loc_4.push(_loc_6);
                    _loc_3.setValue(CookieConsts.USER_LOG_LIST, _loc_4);
                }
            }
            return;
        }// end function

        public static function getInst() : UserLog
        {
            var _loc_1:* = instance || new UserLog;
            instance = instance || new UserLog;
            return _loc_1;
        }// end function

    }
}
